package array
{
	import flash.utils.ByteArray;
	
	import data.Instance;
	import data.Multiname;
	
	import kinds.ClassKind;
	
	import tag.doABC2.CPool;
	
	import util.BytesUtil;
	import util.TraitUtil;

	public dynamic class InstanceArray extends Array
	{
		public function InstanceArray(...parameters)
		{
			super(parameters);
		}
		
		public function fill(bytes:ByteArray, count:uint):void
		{
			var cp:CPool = App.cp;
			if(count > 0){
				var ins:Instance = null;
				for(var i:int = 0;i < count; i++){
					ins = new Instance();
					this[i] = ins;
					ins.name = (cp.cp_multiname[BytesUtil.readU30(bytes)] as Multiname).toString();
					ins.super_name = (cp.cp_multiname[BytesUtil.readU30(bytes)] as Multiname).toString();
					ins.flags = bytes.readUnsignedByte();
					if((ins.flags & 0x08) == ClassKind.CONSTANT_ClassProtectedNs){
						ins.protectedNs = BytesUtil.readU30(bytes);
					}
					var intrf_count:uint = BytesUtil.readU30(bytes);
					for(var n:int = 0; n < intrf_count; n++){
						ins.interfaces[n] = BytesUtil.readU30(bytes);
					}
					ins.iinit = BytesUtil.readU30(bytes);
					var trait_count:uint = BytesUtil.readU30(bytes);
					for(var t:int = 0; t< trait_count; t++){
						ins.traits[i] = TraitUtil.trait(bytes,cp);
					}
				}
			}
		}
		
		
	}
}